package cn.usbtg.session.impl;

import com.jfinal.plugin.activerecord.DbKit;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * db session dao 所需环境配置
 */
public class BTGDBSessionDaoConfig {

    private String dbConfigName; //jfinal db config name
    private String tableName = "BTGSESSION"; // 存放session的表名
    private String sessionIdColumnName = "SESSION_ID"; //存放sessionId的列名
    private String sessionObjColumnName = "SESSION_OBJ"; //存放sessionObj对象的列名

    /**
     * 获取数据库连接
     *
     * @return
     * @throws SQLException
     */
    public Connection getConnection() {
        Connection conn = null;
        try {
            if (null == this.dbConfigName || this.dbConfigName.length() == 0) {
                conn = DbKit.getConfig().getConnection();
            } else {
                conn = DbKit.getConfig(this.dbConfigName).getConnection();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public String getDbConfigName() {
        return dbConfigName;
    }

    public void setDbConfigName(String dbConfigName) {
        if (null != dbConfigName && dbConfigName.length() > 0) {
            this.dbConfigName = dbConfigName;
        }
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        if (null != tableName && tableName.length() > 0) {
            this.tableName = tableName;
        }
    }

    public String getSessionIdColumnName() {
        return sessionIdColumnName;
    }

    public void setSessionIdColumnName(String sessionIdColumnName) {
        if (null != sessionIdColumnName && sessionIdColumnName.length() > 0) {
            this.sessionIdColumnName = sessionIdColumnName;
        }
    }

    public String getSessionObjColumnName() {
        return sessionObjColumnName;
    }

    public void setSessionObjColumnName(String sessionObjColumnName) {
        if (null != sessionObjColumnName && sessionObjColumnName.length() > 0) {
            this.sessionObjColumnName = sessionObjColumnName;
        }
    }
}
